<template>
  <div class="questionlist-page">
    <CommonHeader leftIcon title="提问列表" />
    <EmptyView contentText="暂无内容" buttonText="去添加" :buttonClick="buttonClick" v-show="0==isshow"/>
    <div class="questionlist-list_content">

      <van-pull-refresh
          v-model="refreshing"
          @refresh="onRefresh"
          loosing-text="释放即可刷新"
          pulling-text="下拉刷新">

        <!--        <van-list-->
        <!--            v-model:loading="loading"-->
        <!--            :finished="finished"-->
        <!--            finished-text="没有更多了"-->
        <!--            loading-text="加载中..."-->
        <!--            @load="onLoad">-->

        <div class="questionlist-content" v-for="(item,index) in listData" :key="index" @click="itemClick(item)">
          <div class="questionlist-row">
            <div class="questionlist-row-c1">用户名</div>
            <div class="questionlist-row-c2">{{ item.userName }}</div>
          </div>
          <div class="questionlist-row">
            <div class="questionlist-row-c1">联系方式</div>
            <div class="questionlist-row-c2">{{ item.phone }}</div>
          </div>
          <div class="questionlist-row">
            <div class="questionlist-row-c1">时间</div>
            <div class="questionlist-row-c2">{{ item.createdate }}</div>
          </div>
          <div class="questionlist-row">
            <div class="questionlist-row-c1">问题描述</div>
            <div class="questionlist-row-c2">{{ item.description }}</div>
          </div>
          <div class="questionlist-row">
            <div class="questionlist-row-c1">是否处理</div>
            <div class="questionlist-row-c2 questionlist-row-status">{{ status(item) }}</div>
          </div>
          <div class="questionlist-page_line"></div>
        </div>
        <!--        </van-list>-->
      </van-pull-refresh>
    </div>
  </div>
  <div class="questionlist-button" @click="buttonClick()" v-show="1==isshow">添加</div>
</template>

<script setup>
import '@/views/handbook/css/QuestionListPage.css'
import EmptyView from "@/components/emptyView.vue";
import uiUtil from "@/util/UiUtil.js";
import {reactive, onMounted, inject, provide} from "vue";
import {useRouter, useRoute} from 'vue-router';

const router = useRouter();
const route = useRoute();
////////////////////////////////

const onClickLeft = () => {
  router.back()
}

const isshow = uiUtil.ref(1)
const buttonClick = () => {
  router.push({
    path: uiUtil.routerPath.AddQuestionPage,
    query: {pagetype:'add'}
  })
}

onMounted(() => {
  // uiUtil.vantHeader2()
  initList()
})


const itemData = uiUtil.ref({})
provide('itemData', itemData)
const itemClick = (item) => {
  itemData.value = item
  router.push({
    path: uiUtil.routerPath.AddQuestionPage,
    query: {data: JSON.stringify(item),pagetype:'check'}
  })
}

const status = (item) => {
  if (1 == item.status) {
    return "待处理"
  } else if (2 == item.status) {
    return "已查看"
  } else if (3 == item.status) {
    return "已回复"
  } else {
    return "待处理"
  }
}
/////////请求/////////////////////////////////////


const pageIndex = uiUtil.ref(1)
var ishttp = true
const listData = uiUtil.ref([]);
const initList = () => {
  pageIndex.value = 1
  listData.value = []
  getList()
}
const getList = () => {
  // debugger
  loading.value = false;
  if (!ishttp) return
  ishttp = false
  //品种：品种名称
  //http://202.127.42.144:60011/api/newarchive//api/seedarchive/appHelperQuestion/getAppHelperQuestionList?userid=083b96de-6aab-4c6e-afd2-330896ad8683


  uiUtil.http().getObj({
    url: uiUtil.urlPath.getAppHelperQuestionList + '?userid=',
    start: function start() {
      // uiUtil.toastLoading()
      if (refreshing.value) {
        refreshing.value = false;
      }
    },
    succeed: function succeed(res) {
      if (200 != res.code) {
        uiUtil.toastFail(res.msg)
        return
      }
      if (0 == res.data.length) {
        // 如果返回数据为空，表示已加载完成
        finished.value = true;
        if (listData.value.length == 0) {
          isshow.value = 0
        }
        return;
      }
      // debugger
      if (res.data.length > 0) {
        listData.value.push(...res.data)
        pageIndex.value++
        ishttp = false
      }
    },
    failed: function failed(res) {
      // debugger
      console.log('failed=', res)
      // showFailToast('添加失败')
      uiUtil.toastFail('添加失败')
    },
    finish: function finish() {
      uiUtil.toastClose()
      loading.value = false;
      ishttp = true
    }
  })
};

const loading = uiUtil.ref(false);
const finished = uiUtil.ref(false);
const refreshing = uiUtil.ref(false);
const onLoad = () => {
  getList();
};

const onRefresh = () => {
  initList()
};
////////////////////////////////

</script>

<style scoped lang="less">


</style>